import 'dart:async';

import 'package:event_bus/event_bus.dart';

class A {
  late String name;
}

class ReqEvent {
  late String id;
}

class ResEvent {
  late bool status;
}

EventBus eventBus = EventBus();

void a() {
  StreamSubscription? s;
  s = eventBus.on<ReqEvent>().listen((event) {
    print('---->ReqEvent ${event.id}');
    eventBus.fire(ResEvent()..status = true);
    s?.cancel();
  });
}

void b() {
  StreamSubscription? s;
  s = eventBus.on<ResEvent>().listen((event) {
    print('---->ResEvent ${event.status}');
    eventBus.fire(ResEvent()..status = true);
    s?.cancel();
  });
  eventBus.fire(ReqEvent()..id = 'test');
}

main() {
  eventBus.on<A>().listen((event) {
    print('--->1 ${event.name}');
  });
  StreamSubscription? s;
  s = eventBus.on<A>().listen((event) {
    print('--->2 ${event.name}');
    s?.cancel();
  });
  eventBus.fire(A()..name = "zing");
  eventBus.fire(A()..name = "zing");
  eventBus.fire(A()..name = "zing");

  a();
  b();

  eventBus.fire(ReqEvent()..id = 'test');
}
